/***************************************************************************************************
Copyright 2009 - 2010 Harshana Eranga Martin, Dishan Metihakwala, Rajeev Sampath, Chathura Randika

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
****************************************************************************************************/
//==============================================================================
//                                                                              
//  THIS FILE HAS BEEN GENERATED BY JSTM                                        
//                                                                              
//==============================================================================

package org.epzilla.dispatcher.dispatcherObjectModel;

import jstm.core.*;

public class TriggerInfoObject extends jstm.core.TransactedStructure {

    public TriggerInfoObject() {
        super(FIELD_COUNT);
    }

    public String gettriggerID() {
        return (String) getField(0);
    }

    public void settriggerID(String value) {
        setField(0, value);
    }

    public int getdispatcherId() {
        java.lang.Integer value = (java.lang.Integer) getField(1);

        if(value != null)
            return value.intValue();

        return 0;
    }

    public void setdispatcherId(int value) {
        setField(1, new java.lang.Integer(value));
    }

    public String getclientID() {
        return (String) getField(2);
    }

    public void setclientID(String value) {
        setField(2, value);
    }

    public String getclusterID() {
        return (String) getField(3);
    }

    public void setclusterID(String value) {
        setField(3, value);
    }

    public String getvirtualClusterID() {
        return (String) getField(4);
    }

    public void setvirtualClusterID(String value) {
        setField(4, value);
    }

    public String gettrigger() {
        return (String) getField(5);
    }

    public void settrigger(String value) {
        setField(5, value);
    }

    public String getstratumId() {
        return (String) getField(6);
    }

    public void setstratumId(String value) {
        setField(6, value);
    }

    public String getoldStratumId() {
        return (String) getField(7);
    }

    public void setoldStratumId(String value) {
        setField(7, value);
    }

    public String getoldClusterId() {
        return (String) getField(8);
    }

    public void setoldClusterId(String value) {
        setField(8, value);
    }

    public static final int TRIGGERID_INDEX = 0;

    public static final String TRIGGERID_NAME = "triggerID";

    public static final int DISPATCHERID_INDEX = 1;

    public static final String DISPATCHERID_NAME = "dispatcherId";

    public static final int CLIENTID_INDEX = 2;

    public static final String CLIENTID_NAME = "clientID";

    public static final int CLUSTERID_INDEX = 3;

    public static final String CLUSTERID_NAME = "clusterID";

    public static final int VIRTUALCLUSTERID_INDEX = 4;

    public static final String VIRTUALCLUSTERID_NAME = "virtualClusterID";

    public static final int TRIGGER_INDEX = 5;

    public static final String TRIGGER_NAME = "trigger";

    public static final int STRATUMID_INDEX = 6;

    public static final String STRATUMID_NAME = "stratumId";

    public static final int OLDSTRATUMID_INDEX = 7;

    public static final String OLDSTRATUMID_NAME = "oldStratumId";

    public static final int OLDCLUSTERID_INDEX = 8;

    public static final String OLDCLUSTERID_NAME = "oldClusterId";

    public static final int FIELD_COUNT = 9;

    @Override
    public String getFieldName(int index) {
        return getFieldNameStatic(index);
    }

    public static String getFieldNameStatic(int index) {
        switch (index) {
            case 0:
                return "triggerID";
            case 1:
                return "dispatcherId";
            case 2:
                return "clientID";
            case 3:
                return "clusterID";
            case 4:
                return "virtualClusterID";
            case 5:
                return "trigger";
            case 6:
                return "stratumId";
            case 7:
                return "oldStratumId";
            case 8:
                return "oldClusterId";
            default:
                throw new java.lang.IllegalArgumentException();
        }
    }

    // Internal

    @Override
    protected int getClassId() {
        return 0;
    }

    @Override
    public String getObjectModelUID() {
        return "2sG6AVQttNcts9YIS+QbNw";
    }

    private static final int[] NON_TRANSIENT_FIELDS = new int[] {  };

    @Override
    protected int[] getNonTransientFields() {
        return NON_TRANSIENT_FIELDS;
    }

    @Override
    protected void serialize(TransactedObject.Version version, Writer writer) throws java.io.IOException {
        boolean[] reads = ((TransactedStructure.Version) version).getReads();
        Object[] values = ((TransactedStructure.Version) version).getWrites();

        if (reads != null) {
            writer.writeShort(Short.MAX_VALUE);

            for (int i = 0; i < 9; i++)
                writer.writeBoolean(reads[i]);
        }

        if (values != null) {
            if (values[0] != null) {
                if (values[0] == Removal.Instance)
                    writer.writeShort((short) -1);
                else {
                    writer.writeShort((short) 1);
                    writer.writeString((String) values[0]);
                }
            }

            if (values[1] != null) {
                if (values[1] == Removal.Instance)
                    writer.writeShort((short) -2);
                else {
                    writer.writeShort((short) 2);
                    writer.writeInteger(((java.lang.Integer) values[1]).intValue());
                }
            }

            if (values[2] != null) {
                if (values[2] == Removal.Instance)
                    writer.writeShort((short) -3);
                else {
                    writer.writeShort((short) 3);
                    writer.writeString((String) values[2]);
                }
            }

            if (values[3] != null) {
                if (values[3] == Removal.Instance)
                    writer.writeShort((short) -4);
                else {
                    writer.writeShort((short) 4);
                    writer.writeString((String) values[3]);
                }
            }

            if (values[4] != null) {
                if (values[4] == Removal.Instance)
                    writer.writeShort((short) -5);
                else {
                    writer.writeShort((short) 5);
                    writer.writeString((String) values[4]);
                }
            }

            if (values[5] != null) {
                if (values[5] == Removal.Instance)
                    writer.writeShort((short) -6);
                else {
                    writer.writeShort((short) 6);
                    writer.writeString((String) values[5]);
                }
            }

            if (values[6] != null) {
                if (values[6] == Removal.Instance)
                    writer.writeShort((short) -7);
                else {
                    writer.writeShort((short) 7);
                    writer.writeString((String) values[6]);
                }
            }

            if (values[7] != null) {
                if (values[7] == Removal.Instance)
                    writer.writeShort((short) -8);
                else {
                    writer.writeShort((short) 8);
                    writer.writeString((String) values[7]);
                }
            }

            if (values[8] != null) {
                if (values[8] == Removal.Instance)
                    writer.writeShort((short) -9);
                else {
                    writer.writeShort((short) 9);
                    writer.writeString((String) values[8]);
                }
            }
        }

        writer.writeShort((short) 0);
    }

    @SuppressWarnings("null")
    @Override
    protected void deserialize(TransactedObject.Version version, Reader reader) throws java.io.IOException {
        boolean[] reads = null;
        Object[] values = null;

        short index = reader.readShort();

        if (index == Short.MAX_VALUE) {
            reads = new boolean[9];

            for (int i = 0; i < 9; i++)
                reads[i] = reader.readBoolean();

            index = reader.readShort();
        }

        if (index == 1) {
            if (values == null)
                values = new Object[9];

            values[0] = reader.readString();
            index = reader.readShort();
        } else if (index == -1) {
            if (values == null)
                values = new Object[9];

            values[0] = Removal.Instance;
            index = reader.readShort();
        }

        if (index == 2) {
            if (values == null)
                values = new Object[9];

            values[1] = new java.lang.Integer(reader.readInteger());
            index = reader.readShort();
        } else if (index == -2) {
            if (values == null)
                values = new Object[9];

            values[1] = Removal.Instance;
            index = reader.readShort();
        }

        if (index == 3) {
            if (values == null)
                values = new Object[9];

            values[2] = reader.readString();
            index = reader.readShort();
        } else if (index == -3) {
            if (values == null)
                values = new Object[9];

            values[2] = Removal.Instance;
            index = reader.readShort();
        }

        if (index == 4) {
            if (values == null)
                values = new Object[9];

            values[3] = reader.readString();
            index = reader.readShort();
        } else if (index == -4) {
            if (values == null)
                values = new Object[9];

            values[3] = Removal.Instance;
            index = reader.readShort();
        }

        if (index == 5) {
            if (values == null)
                values = new Object[9];

            values[4] = reader.readString();
            index = reader.readShort();
        } else if (index == -5) {
            if (values == null)
                values = new Object[9];

            values[4] = Removal.Instance;
            index = reader.readShort();
        }

        if (index == 6) {
            if (values == null)
                values = new Object[9];

            values[5] = reader.readString();
            index = reader.readShort();
        } else if (index == -6) {
            if (values == null)
                values = new Object[9];

            values[5] = Removal.Instance;
            index = reader.readShort();
        }

        if (index == 7) {
            if (values == null)
                values = new Object[9];

            values[6] = reader.readString();
            index = reader.readShort();
        } else if (index == -7) {
            if (values == null)
                values = new Object[9];

            values[6] = Removal.Instance;
            index = reader.readShort();
        }

        if (index == 8) {
            if (values == null)
                values = new Object[9];

            values[7] = reader.readString();
            index = reader.readShort();
        } else if (index == -8) {
            if (values == null)
                values = new Object[9];

            values[7] = Removal.Instance;
            index = reader.readShort();
        }

        if (index == 9) {
            if (values == null)
                values = new Object[9];

            values[8] = reader.readString();
            index = reader.readShort();
        } else if (index == -9) {
            if (values == null)
                values = new Object[9];

            values[8] = Removal.Instance;
            index = reader.readShort();
        }

        ((TransactedStructure.Version) version).setReads(reads);
        ((TransactedStructure.Version) version).setWrites(values);
    }
}
